home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE19 / EX4.C < prev    next >
C/C++ Source or Header  |  1995-05-14  |  2KB  |  79 lines

  1. // reg ex4.c
  2.  
  3. #include <windows.h>
  4. #include <winreg.h>
  5. #include <genstub.c>
  6.  
  7. DWORD WINAPI ChildThreadProc( LPTSTR lpszBuffer )
  8. {
  9.    HKEY hKey = 0;
  10.    LONG lErr = RegOpenKeyEx( HKEY_CLASSES_ROOT, "Flush", 0, KEY_ALL_ACCESS, &hKey );
  11.  
  12.    if ( lErr==ERROR_SUCCESS ) {
  13.        lstrcpy( lpszBuffer, "Got Key From Registry!" );
  14.        RegCloseKey( hKey );
  15.    }
  16.    else
  17.        lstrcpy( lpszBuffer, " No Key From Registry! " );
  18.    ExitThread( 1 );
  19. }
  20.  
  21. LRESULT FAR PASCAL WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  22. {
  23.     switch( uMsg )
  24.     {
  25.         case WM_COMMAND:    // process menu items
  26.             switch( wParam )
  27.             {
  28.                 case IDM_TEST: {
  29.                     TCHAR  szBuffer[128];
  30.                     DWORD  dwChildId;
  31.                     DWORD  dwDisposition;
  32.                     HANDLE hChildThread;
  33.                     HKEY   hKey;
  34.  
  35.                     RegCreateKeyEx( HKEY_CLASSES_ROOT, "Flush", 0, "MyClass",
  36.                                     REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  37.                                     NULL, &hKey, &dwDisposition );
  38. //                    RegFlushKey( hKey );
  39.                     hChildThread = CreateThread( NULL, 0, ChildThreadProc,
  40.                                                  szBuffer, 0, &dwChildId );
  41.                     WaitForSingleObject( hChildThread, INFINITE );
  42.                     MessageBox( hWnd, szBuffer, "Flush Key Test", MB_OK );
  43.                     RegDeleteKey( HKEY_CLASSES_ROOT, "FlushTest" );
  44.                 }
  45.                 break;
  46.                 case IDM_EXIT:
  47.                     DestroyWindow( hWnd );
  48.                     break;
  49.             }
  50.         break;
  51.         case WM_DESTROY:
  52.             PostQuitMessage( 0 );
  53.         break;
  54.         default:
  55.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  56.     }
  57.     return( 0L );
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.